#include <bits/stdc++.h>
// 2025/02/04
// tag:
// Author: Zhang Muen
using namespace std;

int l[1000005];

int n, ans = 0;

signed main()
{
    cin >> n;
    deque<int> q;
    for (int i = 1; i <= n; i++) {
        int r;
        cin >> l[i] >> r;
        while (q.size() && l[q.front()] > r)
            q.pop_front();
        if (q.size())
            ans = max(ans, i - q.front() + 1);
        int t = i;
        while (q.size() && l[i] > l[q.back()])
            t = q.back(), q.pop_back();
        l[t] = l[i], q.push_back(t);
    }
    cout << ans;
    return 0;
}